# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=dosbox
_forkname=dosbox-staging
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.78.1
pkgrel=1
pkgdesc="Emulator with builtin DOS for running DOS Games (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://github.com/dosbox-staging/dosbox-staging'
license=('spdx:GPL-2.0-or-later')
depends=(
    "${MINGW_PACKAGE_PREFIX}-fluidsynth"
    "${MINGW_PACKAGE_PREFIX}-libpng"
    "${MINGW_PACKAGE_PREFIX}-opusfile"
    "${MINGW_PACKAGE_PREFIX}-SDL2"
    "${MINGW_PACKAGE_PREFIX}-SDL2_net"
    "${MINGW_PACKAGE_PREFIX}-zlib"
    "${MINGW_PACKAGE_PREFIX}-libslirp"
    "${MINGW_PACKAGE_PREFIX}-munt-mt32emu"
)
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
source=("https://github.com/dosbox-staging/dosbox-staging/archive/refs/tags/v${pkgver}.tar.gz")
sha256sums=('dcd93ce27f5f3f31e7022288f7cbbc1f1f6eb7cc7150c2c085eeff8ba76c3690')

prepare() {
  cd "${srcdir}/${_forkname}-${pkgver}"
}

build() {
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("--buildtype=release")
  else
    extra_config+=("--buildtype=debug")
  fi

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  meson \
    --prefix="${MINGW_PREFIX}" \
    --wrap-mode=nodownload \
    --auto-features=enabled \
    "${extra_config[@]}" \
    -Dunit_tests=disabled \
    ../${_forkname}-${pkgver}

  meson compile
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  meson test
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  DESTDIR="${pkgdir}" meson install

  install -Dm644 "${srcdir}/${_forkname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
